package com.roger.myHome.es.entity;

import java.util.*;
import java.util.stream.*;

public class GroupByExample {
    public static void main(String[] args) {
        // 创建一个包含多个对象的列表
        List<ExpenseApplyDetailSave> people = Arrays.asList(
                new ExpenseApplyDetailSave("2024-01", 25D),
                new ExpenseApplyDetailSave("2024-02", 30D),
                new ExpenseApplyDetailSave("2024-01", 25D),
                new ExpenseApplyDetailSave("2025-01", 30D),
                new ExpenseApplyDetailSave("2025-01", 20d)
        );
        List<NewObj> lastYearList = new ArrayList<>();
        List<NewObj> thisYearList = new ArrayList<>();
        for (ExpenseApplyDetailSave o : people) {
            NewObj no = new NewObj();
            if (o.getBelongMonth().contains("2024")) {
                no.setBelongYear(o.getBelongMonth().substring(0,4));
                no.setMoney(o.getMoney());
                lastYearList.add(no);
            } else {
                no.setBelongYear(o.getBelongMonth().substring(0,4));
                no.setMoney(o.getMoney());
                thisYearList.add(no);
            }
        }

        for (NewObj o : lastYearList) {
            System.out.println(o);
        }

        for (NewObj o : thisYearList) {
            System.out.println(o);
        }

    }



}

